#Import Modules
import os, pygame, time

if not pygame.font: print 'Warning, fonts disabled'
if not pygame.mixer: print 'Warning, sound disabled'

import Game, Config

def main():
    #Initialize Everything
    pygame.init()
    screen = pygame.display.set_mode(Config.WINDOW_SIZE)
    pygame.display.set_caption(Config.GAME_TITLE)

    #Prepare Game Objects
    clock = pygame.time.Clock()
    game = Game.Game()

    if not game.start():
        print "Error Init Game"
        return 1

    ct = time.time()
    #Main Loop
    while 1:
        clock.tick(Config.TICK_TIME)

        if game.pause():
            continue

        if game.over():
            break
        
        #Handle Input Events
        game.handleEvent(pygame.event.get())

        #Tick Game Logic
        lt = ct
        ct = time.time()
        game.tick(ct-lt)

        #Render Everything
        game.render()

    #Close Game
    game.end()
    
    game = None

#Game Over

if __name__ == '__main__': main()
